/**
 * 管理初始化
 */
var TAppList = {
    id: "TAppListTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TAppList.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '小程序名称', field: 'appName', visible: true, align: 'center', valign: 'middle'},
            {title: '标题', field: 'title', visible: true, align: 'center', valign: 'middle'},
            {title: '小程序appid', field: 'appId', visible: true, align: 'center', valign: 'middle'},
            {title: '小程序appSecret', field: 'appSecret', visible: true, align: 'center', valign: 'middle'},
            {title: '跳转类型', field: 'pageType', visible: true, align: 'center', valign: 'middle'},
            {title: '跳转页面Id', field: 'pageId', visible: true, align: 'center', valign: 'middle'},
            {title: '跳转页面Url', field: 'pageUrl', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '创建人', field: 'createId', visible: true, align: 'center', valign: 'middle'},
            {title: '操作', visible: true, align: 'center', valign: 'middle',formatter: formatOperat}
    ];
};

function formatOperat(value, row, index) {
    return ['<button type="button" onclick="manager(\'' + row.appId + '\')" >管理</button>'];
}

function manager(appid){
	localStorage.setItem("appid",appid);//存储变量名为key，值为value的变量  
	window.open(Feng.ctxPath + '/getMainPage?appid='+appid); 
//	window.location.href=;
}

/**
 * 检查是否选中
 */
TAppList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        TAppList.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
TAppList.openAddTAppList = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tAppList/tAppList_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
TAppList.openTAppListDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tAppList/tAppList_update/' + TAppList.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
TAppList.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/tAppList/delete", function (data) {
            Feng.success("删除成功!");
            TAppList.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("tAppListId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
TAppList.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    TAppList.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = TAppList.initColumn();
    var table = new BSTable(TAppList.id, "/tAppList/list", defaultColunms);
    table.setPaginationType("client");
    TAppList.table = table.init();
});
